﻿
@{
    ViewBag.Title = "WxCard";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
}

@section head{

    <link rel="stylesheet" type="text/css" href="~/Content/WxPage.css?d=@DateTime.Now" />
    <link rel="stylesheet" type="text/css" href="~/Scripts/DateJS/date/css/index.css?d=@DateTime.Now" />
    @Scripts.Render("~/bundles/jquery")
    <script src="~/Scripts/DateJS/date/js/date.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    @*@ViewBag.HotelID;*@

}

@{
    //把当前页面的值带给微信服务函数，算出各种令牌和签名，供微信JSAPI
    var otherController = DependencyResolver.Current.GetService<WuYuHotel.Controllers.WxRequestController>();
    Dictionary<string, object> map = otherController.wxPageConfig(Request.Url.ToString());


}
<div onclick="CreadCard()">
    <h2>WxCard</h2>
</div>



<script type="text/javascript">
    //API
    //https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Create_a_membership_card.html
    //图片
    //http://mmbiz.qpic.cn/mmbiz/PiajxSqBRaEIQxibpLbyuSKibIIQhichBVsM74ZxRjzrH99AAFuo8MwNSxJDZNeFuMYC4h7ZM3IN34RjJNE8Wx4oAA/0?wx_fmt=png
    //流程
    //https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&key=1463324905&version=1&lang=zh_CN&platform=2

    wx.config({
        // 配置信息, 即使不正确也能使用 wx.ready
        debug: false,
        appId: '@map["appId"].ToString()',
        timestamp: @map["UNIXTime"].ToString(),
        nonceStr: '@map["noncestr"].ToString()',
        signature: '@map["signature"].ToString()',
        jsApiList: ['addCard', 'chooseCard', 'openCard','openLocation']
    });



    tempjson = {};
    tempjson={
        "card": {
            "card_type": "MEMBER_CARD",
            "member_card": {
                //"background_pic_url": "",
                "base_info": {
                    "logo_url": "http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZ/0",
                    "brand_name": "无隅",
                    "code_type": "CODE_TYPE_TEXT",
                    "title": "无隅酒店会员卡",
                    "color": "Color010",
                    "notice": "使用时向服务员出示此券",
                    "service_phone": "020-88888888",
                    "description": "不可与其他优惠同享",
                    "date_info": {
                        "type": "DATE_TYPE_PERMANENT"
                    },
                    "sku": {
                        "quantity": 0
                    },
                    "get_limit": 1,
                    "use_custom_code": true,
                    "get_custom_code_mode": "GET_CUSTOM_CODE_MODE_DEPOSIT",
                    "can_give_friend": true,
                    //"location_id_list": [123,12321],
                    "custom_url_name": "订房首页",
                    "custom_url": "http://wuyu.cqutlab.cn/wxPage/Index",
                    "custom_url_sub_title": "6个汉字tips",
                    "promotion_url_name": "订房页面",
                    "promotion_url": "http://wuyu.cqutlab.cn/wxPage/MainView",
                    "need_push_on_view": false
                },
                //"advanced_info": {
                //    "use_condition": {
                //        "accept_category": "鞋类",
                //        "reject_category": "阿迪达斯",
                //        "can_use_with_other_discount": true
                //    },
                //    "abstract": {
                //        "abstract": "微信餐厅推出多种新季菜品，期待您的光临",
                //        "icon_url_list": [
                //                "http://mmbiz.qpic.cn/mmbiz/p98FjXy8LacgHxp3sJ3vn97bGLz0ib0Sfz1bjiaoOYA027iasqSG0sjpiby4vce3AtaPu6cIhBHkt6IjlkY9YnDsfw/0"
                //            ]
                //    },
                //    "text_image_list": [
                //        {
                //            "image_url": "http://mmbiz.qpic.cn/mmbiz/p98FjXy8LacgHxp3sJ3vn97bGLz0ib0Sfz1bjiaoOYA027iasqSG0sjpiby4vce3AtaPu6cIhBHkt6IjlkY9YnDsfw/0",
                //            "text": "此菜品精选食材，以独特的烹饪方法，最大程度地刺激食 客的味蕾"
                //        },
                //        {
                //            "image_url": "http://mmbiz.qpic.cn/mmbiz/p98FjXy8LacgHxp3sJ3vn97bGLz0ib0Sfz1bjiaoOYA027iasqSG0sjpiby4vce3AtaPu6cIhBHkt6IjlkY9YnDsfw/0",
                //            "text": "此菜品迎合大众口味，老少皆宜，营养均衡"
                //        }
                //    ],
                //    "time_limit": [
                //        {
                //            "type": "MONDAY",
                //            "begin_hour": 0,
                //            "end_hour": 10,
                //            "begin_minute": 10,
                //            "end_minute": 59
                //        },
                //        {
                //            "type": "HOLIDAY"
                //        }
                //    ],
                //    "business_service": [
                //        "BIZ_SERVICE_FREE_WIFI",
                //        "BIZ_SERVICE_WITH_PET",
                //        "BIZ_SERVICE_FREE_PARK",
                //        "BIZ_SERVICE_DELIVER"
                //    ]
                //},
                "supply_bonus": false,//必填
                "supply_balance": false,
                "prerogative": "test_prerogative",      //会员卡特权说明
                "auto_activate": true,
                //"custom_field1": {
                //    "name_type": "FIELD_NAME_TYPE_LEVEL",
                //    "url": "http://www.qq.com"
                //},
                //"activate_url": "http://www.qq.com",
                //"custom_cell1": {
                //    "name": "使用入口2",
                //    "tips": "激活后显示",
                //    "url": "http://www.qq.com"
                //},
                //"bonus_rule": {
                //    "cost_money_unit": 100,
                //    "increase_bonus": 1,
                //    "max_increase_bonus": 200,
                //    "init_increase_bonus": 10,
                //    "cost_bonus_unit": 5,
                //    "reduce_money": 100,
                //    "least_money_to_use_bonus": 1000,
                //    "max_reduce_bonus": 50
                //},
                //"discount": 10
            }
        }
    }

    function CreadCard() {
        var tempjson2 = JSON.stringify(tempjson);
        $.ajax({
            type: "POST",
            url: "https://api.weixin.qq.com/card/create?access_token=@ViewBag.ACCESS_TOKEN",
            contentType: "application/json;charset=utf-8",
            async: false,
            data: tempjson,
            success: function (msg) {
                alert(msg.errcode);

            }
        });

    }





</script>





